package com.doit.demo01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class test_list {
    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("爸爸",45));
        list.add(new Person("妈妈",45));
        list.add(new Person("爷爷",72));
        list.add(new Person("奶奶",92));

        //使用比较器进行比较 lambda简化
        Collections.sort(list,(p1,p2)->p1.getAge()-p2.getAge());

        list.forEach(p-> System.out.println(p.getName()+" "+p.getAge()));
    }
}
